#region System
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using CF.Framework.Engine.Drawing;
using CF.Framework.Engine.Effects;
using CF.Framework.Engine.Misc;
using CF.Framework.Engine.Screens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
#endregion

namespace CF.Framework.Engine.Controls
{
	public class EffectCollection : IList<Effect>
	{
		private List<Effect> list;
		private Control container;

		internal EffectCollection(Control container)
		{
			this.list = new List<Effect>();
			this.container = container;
		}

		#region IList<Effect> Members

		public int IndexOf(Effect item)
		{
			return list.IndexOf(item);
		}

		public void Insert(int index, Effect item)
		{
			item.Target = container;

			list.Insert(index, item);
		}

		public void RemoveAt(int index)
		{
			var item = list[index];
			item.Target = null;

			list.RemoveAt(index);
		}

		public Effect this[int index]
		{
			get
			{
				return list[index];
			}
			set
			{
				value.Target = container;
				list[index] = value;
			}
		}

		#endregion

		#region ICollection<Effect> Members

		public void Add(Effect item)
		{
			item.Target = container;
			list.Add(item);
		}

		public void Clear()
		{
			while (list.Count > 0)
			{
				list[0].Target = null;
				list.RemoveAt(0);
			}
		}

		public bool Contains(Effect item)
		{
			return list.Contains(item);
		}

		public void CopyTo(Effect[] array, int arrayIndex)
		{
			list.CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get { return list.Count; }
		}

		public bool IsReadOnly
		{
			get { return false; }
		}

		public bool Remove(Effect item)
		{
			item.Target = null;
			return list.Remove(item);
		}

		#endregion

		#region IEnumerable<Effect> Members

		public IEnumerator<Effect> GetEnumerator()
		{
			return list.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return list.GetEnumerator();
		}

		#endregion
	}
}
